package com.jinlia.show.modules.system.auth;

import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
public class AuthController {
    final AuthService authService;

    /**
     * 用户登录
     */
    @PostMapping("token")
    public ResponseEntity<JSONObject> login(@RequestBody @Valid LoginRequest loginRequest) throws Exception {
        // 验证码判断
        JSONObject jsonObject = authService.builderToken(loginRequest);
        return ResponseEntity.ok(jsonObject);
    }

    @PostMapping("/auth/login")
    public ResponseEntity<JSONObject> token(@RequestBody @Valid LoginRequest loginRequest) throws Exception {
        // 验证码判断
        JSONObject jsonObject = authService.builderToken(loginRequest);
        return ResponseEntity.ok(jsonObject);
    }


    @GetMapping("logout")
    public ResponseEntity<Boolean> login() {
        return ResponseEntity.ok(Boolean.TRUE);
    }
}
